/*
 * Copyright 2010 Yannick Stucki (yannickstucki.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.yannickstucki.android.musicqueue.data;

import android.database.Cursor;

import com.yannickstucki.android.musicqueue.util.Logger;

/**
 * A song cursor to obtain all the songs.
 * 
 * @author Yannick Stucki
 * 
 */
public class SongCursorAll implements ISongCursor {

  /**
   * The position of the title in a cursor.
   */
  private static final int CURSOR_POSITION_TITLE = 0;

  /**
   * The position of the album in a cursor.
   */
  private static final int CURSOR_POSITION_ALBUM = 1;

  /**
   * The position of the artist in a cursor.
   */
  private static final int CURSOR_POSITION_ARTIST = 2;

  /**
   * The position of the path in a cursor.
   */
  private static final int CURSOR_POSITION_PATH = 3;

  /**
   * The position of the duration in a cursor.
   */
  private static final int CURSOR_POSITION_DURATION = 4;

  /**
   * The actual cursor.
   */
  private Cursor cursor;

  /**
   * The content resolver to obtain the data.
   */
  private IDatabase database;

  /**
   * The constructor sets the reference.
   */
  public SongCursorAll(IDatabase database) {
    this.database = database;
  }

  @Override
  public boolean query() {
    Logger.debug("before query");
    cursor = database.getSongCursor();
    
    Logger.debug("after query");
    
    return cursor.moveToFirst();
  }

  @Override
  public boolean moveToNext() {
    return cursor.moveToNext();
  }

  @Override
  public Song getSong() {
    return new Song(cursor.getString(CURSOR_POSITION_TITLE), cursor
        .getString(CURSOR_POSITION_ALBUM), cursor.getString(CURSOR_POSITION_ARTIST), cursor
        .getString(CURSOR_POSITION_PATH), cursor.getInt(CURSOR_POSITION_DURATION));
  }
}
